﻿/** 
 * Description:初始化测试数据
 * Date:2011-9-5
 * Author:Along	
*/
package com.community.shopping.web;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
import com.community.shopping.domain.GoodsType;
import com.community.shopping.service.logic.GoodsManager;
import com.community.shopping.service.logic.GoodsTypeManager;

public class TestDataInit {
	
	private GoodsTypeManager goodsTypeManager;	
	
	/**
	 * @param goodsTypeManager the goodsTypeManager to set
	 */
	public void setGoodsTypeManager(GoodsTypeManager goodsTypeManager) {
		this.goodsTypeManager = goodsTypeManager;
	}

	private GoodsManager goodsManager;


	/**
	 * @param goodsManager the goodsManager to set
	 */
	public void setGoodsManager(GoodsManager goodsManager) {
		this.goodsManager = goodsManager;
	}


	public  void init(){
		
		for(int i=0;i<6;i++)
		{
		GoodsType goodsType=new GoodsType();
		goodsType.setTypeName("一级类别 "+i);
		goodsType.setSort(i);
		goodsType.setStatus(1);
		goodsType.setUpGoodType(null);
		goodsType.setLevel(1);
		goodsTypeManager.save(goodsType);
		  for(int j=0;j<4;j++){
			    GoodsType subgoodsType=new GoodsType();
			    subgoodsType.setTypeName("一级类别 "+i+"|"+j);
			    subgoodsType.setSort(j);
			    subgoodsType.setStatus(1);
			    subgoodsType.setUpGoodType(goodsType);
			    subgoodsType.setLevel(2);
				goodsTypeManager.save(subgoodsType);
				for(int k=0;k<4;k++){
				    GoodsType thirdgoodsType=new GoodsType();
				    thirdgoodsType.setTypeName("一级类别 "+i+"|"+j+"|"+k);
				    thirdgoodsType.setSort(k);
				    thirdgoodsType.setStatus(1);
				    thirdgoodsType.setUpGoodType(subgoodsType);
				    thirdgoodsType.setLevel(3);
					goodsTypeManager.save(thirdgoodsType);
			  }
		  }
		}
		
	}
	
	public static void main(String args[]){
		XmlBeanFactory context=new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
		 TestDataInit testData=(TestDataInit)context.getBean("TestDataInit");
		 testData.init();		
		
	}

}
